package lacus.wd_cinema.service;

import lacus.wd_cinema.entity.Hall;
import lacus.wd_cinema.exception.EntityNotFoundException;
import lacus.wd_cinema.repository.HallRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 与放映厅相关的业务类
 * @author lacus
 * @version 0.6
 * @since 0.2
 */
@Service
@Transactional
public class HallService {
    private final HallRepository hallRepository;

    public HallService(HallRepository hallRepository) {
        this.hallRepository = hallRepository;
    }

    /**
     * 根据ID获取放映厅
     * @param id ID
     * @return 放映厅
     */
    public Hall getHallById(String id) {
        return hallRepository.findById(id).orElseThrow(() ->
                new EntityNotFoundException("找不到ID为" + id + "的放映厅"));
    }

    /**
     * 根据影院内所有的放映厅
     * @return 放映厅集合
     */
    public List<Hall> getAllHalls() {
        return hallRepository.findAll();
    }

}
